import groovyx.net.http.HTTPBuilder
import groovy.json.JsonSlurper
import org.apache.commons.lang.StringUtils

def baseUrl = "http://api.stackexchange.com/2.0/"

def careersProfiles = []
for (int i = 1; i < 20; i++) {

    def http = new HTTPBuilder(baseUrl)

    http.get(path: 'users',
            query: [page: i, site: "stackoverflow"]) { resp, json ->

        def jsonText = new JsonSlurper().parseText(json.toString())
        jsonText.items.each {item ->
            //println item
            if (StringUtils.containsIgnoreCase(item.link?.toString(), "careers.stackoverflow.com")) {
                println(item.link)
                careersProfiles << item.link
            }
            if (StringUtils.containsIgnoreCase(item.website_url?.toString(), "careers.stackoverflow.com")) {
                println(item.website_url)
                careersProfiles << item.link
            }
        }

    }
}
println "total profiles found :${careersProfiles.size()}"
careersProfiles.each {
    def file = new FileOutputStream(it.tokenize("/")[-1])
    def out = new BufferedOutputStream(file)
    out << new URL(it).openStream()
    out.close()
}